package com.example.factory.presenter.contact;

import com.example.common.factory.data.DataSource;
import com.example.common.factory.presenter.BasePresenter;
import com.example.factory.data.helper.UserHelper;
import com.example.factory.model.card.UserCard;

import net.qiujuer.genius.kit.handler.Run;
import net.qiujuer.genius.kit.handler.runable.Action;

/**
 * @author:0.2℃
 * @date： 2022-01-16 19:19
 * @version:
 * @Description ：
 */
public class FollowPresenter extends BasePresenter<FollowContract.View>
        implements FollowContract.Presenter, DataSource.Callback<UserCard> {

    public FollowPresenter(FollowContract.View view) {
        super(view);
    }

    @Override
    public void onDataLoaded(final UserCard userCard) {
        FollowContract.View followView = getView();
        if (followView != null) {
            Run.onUiAsync(new Action() {
                @Override
                public void call() {
                    followView.onFollowSucceed(userCard);
                }
            });
        }
    }

    @Override
    public void onDataNotAvailable(int strRes) {
        FollowContract.View followView = getView();
        if (followView != null) {
            Run.onUiAsync(new Action() {
                @Override
                public void call() {
                    followView.showError(strRes);
                }
            });
        }
    }

    @Override
    public void follow(String userId) {
        start();
        UserHelper.follow(userId, this);
    }
}
